#include "myapp.h"
#include "dbkakeibo.h"

DECLARE_APP(MyApp);
#include <wx/arrimpl.cpp>
WX_DEFINE_OBJARRAY(DBL_periodical);
WX_DEFINE_OBJARRAY(DBL_holiday);
WX_DEFINE_OBJARRAY(DBL_reserved);
WX_DEFINE_OBJARRAY(DBL_WeeklyReport);

//--------------------------------------------------------------
// DB_kakeibo
//--------------------------------------------------------------
DB_kakeibo::DB_kakeibo(void)
{
	CountBudget = 0;
	CountTotal = 0;
	CountExpense = 0;
	CountItems = 0;
	CountAccount = 0;
}
//---------------------------------------------------------------
// add paramater data in DB
//---------------------------------------------------------------
int DB_kakeibo::AddBudget(DB_day db)
{
	wxString sql = StrF(_T("insert into db_budgets values ( '%s', %d, %d, %d, %d, %d, %d, %d, '%s', '%s' );"),
		db.GetDate().Format(DATEFORM).c_str(), db.GetId(), db.GetIO(),
		db.GetHandling(), db.GetExpense(), db.GetItems(),
		db.GetIncome(), db.GetExpenditure(), db.GetMemo().c_str(), db.GetExtra().c_str());
	return wxGetApp().SQLDB().ExecuteUpdate(sql);
}
int DB_kakeibo::AddTotal(DB_total db)
{
	wxString sql = StrF(_T("insert into db_total values ( '%s', %d, %d, %d, %d );"),
		db.GetDate().Format(DATEFORM).c_str(),db.GetHandling(),db.GetIncome(),
		db.GetExpenditure(),db.GetRemainder());
	return wxGetApp().SQLDB().ExecuteUpdate(sql);

}
int DB_kakeibo::AddExpense(DB_expense db)
{
	wxString sql = StrF(_T("insert into db_expense(ex_io,ex_image,ex_name,ex_account) values ( %d, %d, '%s', '%s' );"),
		db.GetIO(),db.GetImage(),db.GetName().c_str(),(db.GetAccount() ? _T("1") : _T("0")));
	return wxGetApp().SQLDB().ExecuteUpdate(sql);
}
int DB_kakeibo::AddItems(DB_items db)
{
	wxString sql = wxString::Format(_T("insert into db_items(it_id,it_image,it_expense,it_name) values ( %d, %d, %d, '%s' );"),
		db.GetId(),db.GetImage(),db.GetExpense(),db.GetName().c_str());
	return wxGetApp().SQLDB().ExecuteUpdate(sql);
}
int DB_kakeibo::AddAccount(DB_account db)
{
	wxString sql = wxString::Format(_T("insert into db_account(ac_name,ac_initial) values ( '%s', %d );"),
		db.GetName().c_str(),db.GetRemain());
	return wxGetApp().SQLDB().ExecuteUpdate(sql);
}
int DB_kakeibo::AddPeriod(DB_periodical db)
{
	wxString sql = StrF(_T("insert into db_period(%s, %s) values('%s',%d,%d,%d,'%s','%s',%d,%d,%d,%d,%d,%d,'%s')"),
		_T("pr_date, pr_periodtype, pr_day, pr_holiday, pr_inputval, pr_inputmemo "),
		_T("pr_io, pr_handle, pr_expense, pr_items, pr_income, pr_expenditure, pr_memo"),
		db.GetDate().Format(DATEFORM).c_str(),db.GetTiming(),db.GetTimingDay(),db.GetHoliday(),
		(db.GetInputValue() ? _T("1") : _T("0")),(db.GetInputMemo() ? _T("1") : _T("0")),
		(int)(db.GetBudget().GetIO()),db.GetBudget().GetHandling(),
		db.GetBudget().GetExpense(),db.GetBudget().GetItems(),
		db.GetBudget().GetIncome(),db.GetBudget().GetExpenditure(),
		db.GetBudget().GetMemo().c_str());
	return wxGetApp().SQLDB().ExecuteUpdate(sql);
}
int DB_kakeibo::AddReserved(DB_reserved db)
{
	wxString sql = wxString::Format(_T("insert into db_reserved(rs_type,rs_handle,rs_start,rs_end,rs_budget) values ( %d,%d,'%s','%s', %d );"),
		db.GetType(),db.GetHandling(),db.GetStartDate().Format(DATEFORM).c_str(),
		db.GetEndDate().Format(DATEFORM).c_str(),db.GetValue());
	return wxGetApp().SQLDB().ExecuteUpdate(sql);
}
//---------------------------------------------------------------
// replace existed DB data to paramater data 
//---------------------------------------------------------------
void DB_kakeibo::SetBudget(DB_day cond, DB_day db)
{
	wxString sql = StrF(_T("update db_budgets set bg_date = '%s', bg_io = %d, bg_handle = %d, bg_expense = %d, bg_items = %d, bg_income = %d, bg_expenditure = %d, bg_memo = '%s', bg_extra = '%s' where bg_date = '%s' and bg_id = %d and bg_io = %d and bg_handle = %d;"),
		db.GetDate().Format(DATEFORM).c_str(), db.GetIO(), db.GetHandling(), db.GetExpense(),
		db.GetItems(),db.GetIncome(), db.GetExpenditure(),
		db.GetMemo().c_str(),db.GetExtra().c_str(),
		cond.GetOldDate().Format(DATEFORM).c_str(), cond.GetId(),cond.GetIO(), cond.GetHandling());
	wxGetApp().SQLDB().ExecuteUpdate(sql);
}
void DB_kakeibo::SetExpense(int index, DB_expense db)
{
	wxString sql = StrF(_T("update db_expense set ex_image = %d, ex_name = '%s', ex_account = '%s' where ex_id = %d;"),
		db.GetImage(),db.GetName().c_str(),(db.GetAccount() ? _T("1") : _T("0")),index);
	wxGetApp().SQLDB().ExecuteUpdate(sql);

}
void DB_kakeibo::SetItems(DB_items cond, DB_items db)
{
	wxString sql = StrF(_T("update db_items set it_id = %d, it_image = %d, it_name = '%s' where it_id = %d and it_expense = %d;"),
		db.GetId(),db.GetImage(),db.GetName().c_str(),cond.GetId(),cond.GetExpense());
	wxGetApp().SQLDB().ExecuteUpdate(sql);
}
void DB_kakeibo::SetAccount(int index, DB_account db)
{
	wxString sql = StrF(_T("update db_account set ac_name = '%s', ac_initial = %d where ac_id = %d;"),
		db.GetName().c_str(),db.GetRemain(),index);
	wxGetApp().SQLDB().ExecuteUpdate(sql);
}
void DB_kakeibo::SetTotal(DB_total cond, DB_total db)
{
	wxString sql = StrF(_T("update db_total set tot_income = %d, tot_expenditure = %d, tot_remainder = %d where tot_date = '%s' and tot_handle = %d;"),
		db.GetIncome(),db.GetExpenditure(),db.GetRemainder(),cond.GetDate().Format(DATEFORM).c_str(),cond.GetHandling());
	wxGetApp().SQLDB().ExecuteUpdate(sql);

}
void DB_kakeibo::SetPeriod(DB_periodical cond, DB_periodical db)
{
	wxString sql[3];
	sql[0] = StrF(_T("update db_period set pr_date = '%s', pr_periodtype = %d, pr_day = %d, pr_holiday = %d, "),
		db.GetDate().Format(DATEFORM).c_str(),db.GetTiming(),db.GetTimingDay(),db.GetHoliday());
	sql[1] = StrF(_T("pr_inputval = '%s', pr_inputmemo = '%s', pr_io = %d, pr_handle = %d, "),
		(db.GetInputValue() ? _T("1") : _T("0")),(db.GetInputMemo() ? _T("1") : _T("0")),
		(int)(db.GetBudget().GetIO()),db.GetBudget().GetHandling());
	sql[2] = StrF(_T("pr_expense = %d, pr_items = %d, pr_income = %d, pr_expenditure = %d, pr_memo = '%s' where pr_id = %d;"),
		db.GetBudget().GetExpense(),db.GetBudget().GetItems(),
		db.GetBudget().GetIncome(),db.GetBudget().GetExpenditure(),
		db.GetBudget().GetMemo().c_str(),cond.GetId());
	wxGetApp().SQLDB().ExecuteUpdate(sql[0]+sql[1]+sql[2]);
}
void DB_kakeibo::SetReserved(DB_reserved cond, DB_reserved db)
{
	wxString sql = StrF(_T("update db_reserved set rs_type = %d, rs_handle = %d, rs_start = '%s', rs_end = '%s', rs_value = %d where rs_id = %d;"),
		db.GetType(),db.GetHandling(),db.GetStartDate().Format(DATEFORM).c_str(),
		db.GetEndDate().Format(DATEFORM).c_str(),db.GetValue(),cond.GetId());
	wxGetApp().SQLDB().ExecuteUpdate(sql);

}
vector<DB_day> DB_kakeibo::GetContent(operatorType oper, DB_day cond1, DB_day cond2)
{
	char flags[8];
	memset(flags, 0, sizeof(flags));
	vector<DB_day> result;
	vector<DB_day>::iterator it;
	
	return result;
}
//---------------------------------------------------------------
// get DB data with condition of paramater
//---------------------------------------------------------------
DB_total DB_kakeibo::GetTotal(DB_total cond)
{
	DB_total result;
	
	wxString sql = StrF(_T("select * from db_total where tot_date = '%s' and tot_handle = %d;"),
		cond.GetDate().Format(DATEFORM).c_str(),cond.GetHandling());
	wxSQLite3ResultSet rset = wxGetApp().SQLDB().ExecuteQuery(sql);
	while (rset.NextRow()) {
		result.SetDate(rset.GetDate(0));
		result.SetHandling(rset.GetInt(1));
		result.SetIncome(rset.GetInt(2));
		result.SetExpenditure(rset.GetInt(3));
		result.SetRemainder(rset.GetInt(4));
	}
	
	return result;
}
DB_total DB_kakeibo::GetTotalNear(DB_total cond, wxString judge)
{
	DB_total result;
	wxString sql = StrF(_T("select * from db_total where tot_date %s '%s' and tot_handle = %d order by tot_date desc limit 1;"),
		judge.c_str(),cond.GetDate().Format(DATEFORM).c_str(),cond.GetHandling());
	wxSQLite3ResultSet rset = wxGetApp().SQLDB().ExecuteQuery(sql);
	while (rset.NextRow()) {
		result.SetDate(rset.GetDate(0));
		result.SetHandling(rset.GetInt(1));
		result.SetIncome(rset.GetInt(2));
		result.SetExpenditure(rset.GetInt(3));
		result.SetRemainder(rset.GetInt(4));
		break;
	}
	return result;
}
DB_expense DB_kakeibo::GetExpense(int id, int io)
{
	DB_expense result;
	
	wxString sql = StrF(_T("select * from db_expense where ex_id = %d and ex_io = %d;"),
		id,io);
	wxSQLite3ResultSet rset = wxGetApp().SQLDB().ExecuteQuery(sql);
	while (rset.NextRow()) {
		result.SetId(rset.GetInt(0));
		result.SetIO((InoutType)rset.GetInt(1));
		result.SetImage(rset.GetInt(2));
		result.SetName(rset.GetString(3));
		result.SetAccount(rset.GetString(4) == _T("1") ? true : false);
	}
	return result;
}
DB_items DB_kakeibo::GetItems(int id, int expense)
{
	DB_items result;
	
	wxString sql = StrF(_T("select * from db_items where it_id = %d and it_expense = %d;"),
		id,expense);
	wxSQLite3ResultSet rset = wxGetApp().SQLDB().ExecuteQuery(sql);
	while (rset.NextRow()) {
		result.SetId(rset.GetInt(0));
		result.SetImage(rset.GetInt(1));
		result.SetExpense(rset.GetInt(2));
		result.SetName(rset.GetString(3));
	}
	
	return result;
}
DB_account DB_kakeibo::GetAccount(int id)
{
	DB_account result;
	
	wxString sql = StrF(_T("select * from db_account where ac_id = %d;"),id);
	wxSQLite3ResultSet rset = wxGetApp().SQLDB().ExecuteQuery(sql);
	while (rset.NextRow()) {
		result.SetId(rset.GetInt(0));
		result.SetName(rset.GetString(1));
		result.SetRemain(rset.GetInt(2));
	}
	
	return result;
}
//---------------------------------------------------------------
// get DB data number in paramater condition
//---------------------------------------------------------------
int DB_kakeibo::GetBudgetCount(DB_day db)
{
	wxString sql = StrF(_T("select count(*) from db_budgets where bg_date = '%s'"),
		db.GetDate().Format(DATEFORM).c_str());
	return wxGetApp().SQLDB().ExecuteScalar(sql);
}
int DB_kakeibo::GetTotalCount(DB_total db)
{
	wxString sql = StrF(_T("select count(*) from db_total where tot_date = '%s' and tot_handle = %d"),
		db.GetDate().Format(DATEFORM).c_str(),db.GetHandling());
	return wxGetApp().SQLDB().ExecuteScalar(sql);

}
//---------------------------------------------------------------
// get last id number with condition of paramater
//---------------------------------------------------------------
int DB_kakeibo::GetLastIdOfBudget(const wxDateTime &date, int io, int handling)
{
	wxString sql = _T("select %s(bg_id) from db_budgets where bg_date = '%s' and bg_io = %d and bg_handle = %d");
	int cnt = wxGetApp().SQLDB().ExecuteScalar(
		StrF(sql,_T("count"),date.Format(DATEFORM).c_str(),io,handling));
	if (cnt == 0) {
		return 0;
	}else{
		return wxGetApp().SQLDB().ExecuteScalar(
			StrF(sql,_T("max"),date.Format(DATEFORM).c_str(),io,handling)) + 1;
	}

}
int DB_kakeibo::GetLastIdOfItems(int expense)
{
	wxString sql = _T("select %s(it_id) from db_items where it_expense = %d");
	int cnt = wxGetApp().SQLDB().ExecuteScalar(
		StrF(sql,_T("count"),expense));
	if (cnt == 0) {
		return 0;
	}else{
		return wxGetApp().SQLDB().ExecuteScalar(
			StrF(sql,_T("max"),expense)) + 1;
	}

}
//---------------------------------------------------------------
// check if paramater date is work day
//---------------------------------------------------------------
bool DB_kakeibo::IsWorkDayExtra(const wxDateTime &date)
{
	int cnt = AppSetting.GetHolidayCount();
	for (int i = 0; i < cnt; i++) {
		if ((date.GetMonth() == AppSetting.GetHoliday(i).GetDate().GetMonth()) &&
			(date.GetDay() == AppSetting.GetHoliday(i).GetDate().GetDay())) {
			return false;
		}
	}
	if (date.GetWeekDay() == wxDateTime::Sun) {
		return false;
	}else if (date.GetWeekDay() == wxDateTime::Sat) {
		return false;
	}else{
		return true;
	}
}
wxArrayString DB_kakeibo::GetStringDayTransaction(DB_day &db)
{
	wxArrayString arr;
	int imageid[2];
	arr.Add(db.GetDate().Format(DATEFORM));		//0:Date
	arr.Add(GetExpense(db.GetExpense(),db.GetIO()).GetName());		//1:Expense
	imageid[0] = this->GetExpense(db.GetExpense(),db.GetIO()).GetImage();
	arr.Add(GetItems(db.GetItems(),db.GetExpense()).GetName());		//2:Item
	imageid[1] = this->GetItems(db.GetItems(),db.GetExpense()).GetImage();
	arr.Add(GetAccount(db.GetHandling()).GetName());	//3:Account
	arr.Add(IntToStr(db.GetIncome()));					//4:Income
	arr.Add(IntToStr(db.GetExpenditure()));				//5:Expenditure
	arr.Add(db.GetMemo());								//6:Memo
	return arr;
}
//--------------------------------------------------------------
// DB_setting
//--------------------------------------------------------------
void DB_setting::SetPeriod(int index, DB_periodical &db)
{
	period.Insert(db,index,1);
	RemovePeriod(index+1);
}
void DB_setting::RemovePeriod(int index)
{
	//DB_periodical *item = period[index];
	//delete item;
	period.RemoveAt(index);
}
void DB_setting::SetHoliday(int index, DB_holiday &db)
{
	holiday.Insert(db,index,1);
	RemoveHoliday(index+1);
}
void DB_setting::RemoveHoliday(int index) 
{
	//DB_holiday *item = holiday[index];
	//delete item;
	holiday.RemoveAt(index);
}
void DB_setting::SetBudget(int index, DB_reserved &db)
{
	reserved.Insert(db,index,1);
	RemoveBudget(index+1);
}
void DB_setting::RemoveBudget(int index)
{
	reserved.RemoveAt(index);
}
void DB_setting::SetRecent(int index, const wxString &file)
{
	recentfiles.Item(index) = file;
}
void DB_setting::RemoveRecent(int index)
{
	recentfiles.RemoveAt(index);
}
void DB_setting::PushRecent(const wxString &file, bool enable_pop)
{
	AddRecent(file);
	if (enable_pop && (GetRecentCount() >= 5)) {
		RemoveRecent(0);
	}
}
void DB_setting::PopRecent(void)
{
	RemoveRecent(0);
}

void DB_setting::LoadDB(void)
{
	wxString sql = _T("select * from db_config;");
	wxSQLite3ResultSet rset = wxGetApp().SQLDB().ExecuteQuery(sql);
	while (rset.NextRow()) {
		if (rset.GetString(0) == _T("cf_startdate")) {
			startdate = rset.GetDate(1);
		}else if (rset.GetString(0) == _T("cf_settlingday")) {
			settleday = rset.GetInt(1);
		}else if (rset.GetString(0) == _T("cf_settlinglastday")) {
			settlelastday = rset.GetString(1) == _T("1") ? true : false;
		}else if (rset.GetString(0) == _T("cf_settlingmonth")) {
			settlemonth = rset.GetInt(1);
		}else if (rset.GetString(0) == _T("cf_username")) {
			username = rset.GetString(1);
		}else if (rset.GetString(0) == _T("cf_bookname")) {
			bookname = rset.GetString(1);
		}
	}
	period.Clear();
	sql = _T("select * from db_period;");
	rset = wxGetApp().SQLDB().ExecuteQuery(sql);
	while (rset.NextRow()) {
		DB_periodical perdb;
		DB_day db;
		perdb.SetId(rset.GetInt(0));
		perdb.SetDate(rset.GetDate(1));
		perdb.SetTiming(rset.GetInt(2));
		perdb.SetTimingDay(rset.GetInt(3));
		perdb.SetHoliday(rset.GetInt(4));
		perdb.SetInputValue(rset.GetString(5) == _T("1") ? true : false);
		perdb.SetInputMemo(rset.GetString(6) == _T("1") ? true : false);
		db.SetIO((InoutType)rset.GetInt(7));
		db.SetHandling(rset.GetInt(8));
		db.SetExpense(rset.GetInt(9));
		db.SetItems(rset.GetInt(10));
		db.SetIncome(rset.GetInt(11));
		db.SetExpenditure(rset.GetInt(12));
		db.SetMemo(rset.GetString(13));
		perdb.SetBudget(db);
		period.Add(perdb);
	}
	reserved.Clear();
	sql = _T("select * from db_reserved;");
	rset = wxGetApp().SQLDB().ExecuteQuery(sql);
	while (rset.NextRow()) {
		DB_reserved db;
		db.SetId(rset.GetInt(0));
		db.SetType(rset.GetInt(1));
		db.SetHandling(rset.GetInt(2));
		db.SetStartDate(rset.GetDate(3));
		db.SetEndDate(rset.GetDate(4));
		db.SetValue(rset.GetInt(5));
		reserved.Add(db);
	}
}
void DB_setting::WriteConfig(const wxString &name, const wxString &val)
{
	if (wxGetApp().SQLDB().ExecuteScalar(StrF(_T("select count(*) from db_config where cf_name = '%s'"),
		name.c_str())) == 0) {
		wxGetApp().SQLDB().ExecuteQuery(StrF(_T("insert into db_config values('%s','%s');"),
			name.c_str(),val.c_str()));
	}else{
		wxGetApp().SQLDB().ExecuteUpdate(
			StrF(_T("update db_config set cf_value = '%s' where cf_name = '%s';"),
			val.c_str(),name.c_str()));
	}
}
void DB_setting::WriteConfig(const wxString &name, int val)
{
	if (wxGetApp().SQLDB().ExecuteScalar(StrF(_T("select count(*) from db_config where cf_name = '%s'"),
		name.c_str())) == 0) {
		wxGetApp().SQLDB().ExecuteQuery(StrF(_T("insert into db_config values('%s','%d');"),
			name.c_str(),val));
	}else{
		wxGetApp().SQLDB().ExecuteUpdate(
			StrF(_T("update db_config set cf_value = '%d' where cf_name = '%s';"),
			val,name.c_str()));
	}
}
void DB_setting::WriteConfig(const wxString &name, bool val)
{
	if (wxGetApp().SQLDB().ExecuteScalar(StrF(_T("select count(*) from db_config where cf_name = '%s'"),
		name.c_str())) == 0) {
		wxGetApp().SQLDB().ExecuteQuery(StrF(_T("insert into db_config values('%s','%d');"),
			name.c_str(),(val ? 1 : 0)));
	}else{
		wxGetApp().SQLDB().ExecuteUpdate(
			StrF(_T("update db_config set cf_value = '%d' where cf_name = '%s';"),
			(val ? 1 : 0),name.c_str()));
	}
}
//--------------------------------------------------------------
// DB_day
//--------------------------------------------------------------
DB_day::DB_day(const DB_day &day):DB_base(day)
{
	db_date = day.db_date;
	iotype = day.iotype;
	db_id = day.db_id;
	expenseid = day.expenseid;
	itemsid = day.itemsid;
	handling = day.handling;
	db_income = day.db_income;
	db_expenditure = day.db_expenditure;
	db_memo = day.db_memo;
	db_extra = day.db_extra;
	olddate = day.olddate;
}
DB_day &DB_day::operator=(const DB_day &day)
{
	if (this == &day) return *this;
	DB_base::operator=(day);
	db_date = day.db_date;
	iotype = day.iotype;
	db_id = day.db_id;
	expenseid = day.expenseid;
	itemsid = day.itemsid;
	handling = day.handling;
	db_income = day.db_income;
	db_expenditure = day.db_expenditure;
	db_memo = day.db_memo;
	db_extra = day.db_extra;
	olddate = day.olddate;
	return *this;
}
void DB_day::Clear(void)
{
	db_date = wxDateTime::Now();
	iotype = in_it;
	db_id = -1;
	expenseid = -1;
	itemsid = -1;
	handling = -1;
	db_income = 0;
	db_expenditure = 0;
	db_memo.Clear();
	db_extra.Clear();
	olddate = wxDateTime::Now();
}
//--------------------------------------------------------------
// DB_total
//--------------------------------------------------------------
DB_total::DB_total(const DB_total &db):DB_base(db)
{
	db_date = db.db_date;
	handling = db.handling;
	db_income = db.db_income;
	db_expenditure = db.db_expenditure;
	db_value = db.db_value;
}
DB_total &DB_total::operator=(const DB_total &db)
{
	if (this == &db) return *this;
	DB_base::operator=(db);
	db_date = db.db_date;
	handling = db.handling;
	db_income = db.db_income;
	db_expenditure = db.db_expenditure;
	db_value = db.db_value;
	return *this;
}
void DB_total::Clear(void)
{
	db_date = wxDateTime::UNow();
	handling = -1;
	db_income = -1;
	db_expenditure = -1;
	db_value = 0;
}
//--------------------------------------------------------------
// DB_expense
//--------------------------------------------------------------
DB_expense::DB_expense(const DB_expense &db):DB_base(db)
{
	key = db.key;
	iotype = db.iotype;
	image = db.image;
	label = db.label;
	haveaccount = db.haveaccount;

}
void DB_expense::Clear(void)
{
	key = -1;
	iotype = in_it;
	image = -1;
	label.Clear();
	haveaccount = false;
}
DB_expense &DB_expense::operator=(const DB_expense &db)
{
	if (this == &db) return *this;
	DB_base::operator=(db);
	key = db.key;
	iotype = db.iotype;
	image = db.image;
	label = db.label;
	haveaccount = db.haveaccount;
	return *this;
}
//--------------------------------------------------------------
// DB_WeeklyReport
//--------------------------------------------------------------
DB_WeeklyReport::DB_WeeklyReport(void)
{
	Clear();
}
void DB_WeeklyReport::Clear(void)
{
	expensename.Clear();
	itemname.Clear();
	for (int i = 0; i < WXSIZEOF(isexist); i++) isexist[i] = false;
	for (int i = 0; i < WXSIZEOF(itemdate); i++) itemdate[i] = wxDateTime::Today();
	for (int i = 0; i < WXSIZEOF(itemamount); i++) itemamount[i] = 0;
	for (int i = 0; i < WXSIZEOF(itemio); i++) itemio[i] = none_it;
}
void DB_WeeklyReport::SetExpenseName(const wxString &expense)
{
	expensename = expense;
}
void DB_WeeklyReport::SetItemName(const wxString &item)
{
	itemname = item;
}
void DB_WeeklyReport::SetData(int index, bool exist)
{
	isexist[index] = exist;
	if (!isexist[index]) {
		itemdate[index] = wxDateTime::Today();
		itemamount[index] = 0;
		itemio[index] = none_it;
	}
}
void DB_WeeklyReport::SetItemDate(int index, wxDateTime date)
{
	itemdate[index] = date;
	isexist[index] = true;
}
void DB_WeeklyReport::SetAmount(int index, int amt)
{
	itemamount[index] = amt;
	isexist[index] = true;
}
void DB_WeeklyReport::SetIO(int index, InoutType io)
{
	itemio[index] = io;
	isexist[index] = true;
}
